package com.example.service;

import cn.hutool.core.util.StrUtil;
import com.example.domain.Account;
import com.example.domain.Article;
import com.example.exception.CustomException;
import com.example.mapper.ArticleMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleService {

    @Autowired
    ArticleMapper articleMapper;

    //    查全部数据
    public List<Article> selectAll(Article article) {
        return articleMapper.selectAll(article);
    }

    //    查单个数据
    public Article selectByPrimaryKey(Long id) {
        return articleMapper.selectByPrimaryKey(id);
    }

    //    分页查询
    public PageInfo<Article> selectPage(Article article, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Article> list = articleMapper.selectAll(article);
        return PageInfo.of(list);
    }

    // 新增数据
    public void add(Article article) {
        articleMapper.insert(article);
    }

    //根据id 更新数据
    public void update(Article article) {

        articleMapper.updateByPrimaryKey(article);

    }

    //根据id  删除数据
    public void deleteById(Integer id) {
        articleMapper.deleteByPrimaryKey(id);
    }
    
}
